package com.designpatterns.flyweight.flyweightfactory;

import java.util.HashMap;
import java.util.Map;

import com.designpatterns.flyweight.concreteflyweight.FlyweightImpl;
import com.designpatterns.flyweight.flyweight.Flyweight;

/**
 * FlyweightFactory Class
 *
 * @author Haiqi.Wang
 * @since 2013-6-8下午7:21:02
 */
public class FlyweightFactory {
	private static Map<String, Flyweight> flyweights = new HashMap<String, Flyweight>();
	
	/**
	 * Argument Constructor
	 * @param arg Strings
	 */
	public FlyweightFactory(String arg) {
		flyweights.put(arg, new FlyweightImpl());
	}
	
	/**
	 * According the <code>key</code> Get the <code>Flyweight</code> Interface Object
	 * @param key	key
	 * @return	Flyweight Object
	 */
	public static Flyweight getFlyweight(String key) {
		if (flyweights.get(key) == null) {
			flyweights.put(key, new FlyweightImpl());
		}
		return flyweights.get(key);
	}
	
	/**
	 * Get Collection Size
	 * @return Collection Size
	 */
	public static int getSize() {
		return flyweights.size();
	}
}
